﻿using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using Xunit;

namespace AopOfUnityDemo
{
    /// <summary>
    /// Unity.Interception测试
    /// http://www.cnblogs.com/gaochundong/archive/2013/06/01/aop_interception_with_unity.html
    /// 注意：需要先下载Nuget包：“Unity.Interception”
    /// </summary>
    public class UnityInterceptionTest2
    {
        private static readonly UnityContainer container = new UnityContainer();

        static UnityInterceptionTest2()
        {
            container.AddNewExtension<Interception>();
            container.RegisterType<ICalculator, MyCalculator>()
                .Configure<Interception>()
                .SetInterceptorFor<ICalculator>(new InterfaceInterceptor());
        }

        [Fact]
        public void Test1()
        {
            ICalculator calc = container.Resolve<ICalculator>();
            var result = calc.Add(1, 2);
            Assert.Equal(3, result);
        }
    }
}